def is_prime(num):
    if num < 2:
        return False
    return all(num % i != 0 for i in range(2, int(num**0.5) + 1))

words_to_nums = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9
}

input_str = input()
words = input_str.split()

if len(words) != 3:
    print("Wrong input")
    quit()

word1, word2, word3 = words

if word1 not in words_to_nums or word2 not in words_to_nums or word3 not in words_to_nums:
    print("Wrong input")
    quit()
    
number = words_to_nums[word1] * 100 + words_to_nums[word2] * 10 + words_to_nums[word3]

if 100 <= number <= 999:
    lower_prime = number
    upper_prime = number
    while not is_prime(lower_prime):
        lower_prime -= 1
    while not is_prime(upper_prime):
        upper_prime += 1
    
    if number - lower_prime <= upper_prime - number:
        print(lower_prime)
    else:
        print(upper_prime)
else:
    print("Wrong input")